package com.example.myxmpp.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

import com.example.myxmpp.utils.ToastUtils;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;

public class PushService  extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {

        //广播接收
        //IMService.conn.addSyncStanzaListener();
          IMService.conn.addAsyncStanzaListener(new PacketListener() {
              @Override
              public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException {
                  Log.i("packet","=============="+packet.toXML(null)+"===============");
                  Message message = (Message) packet;
                  String body = message.getBody();

                  ToastUtils.showToastSafe(getApplicationContext(),body);
              }
          },null);
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
